﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Portal.Core;
using Portal.Cms.Utility;
using Portal.Web.Utility;
using Portal.Cms.Model;
using System.Collections.ObjectModel;

namespace Portal.Cms.PorletData.Service
{
    public class PorletDataNewsService : PorletDataTemplate
    {
        public override string ServiceId
        {
            get
            {
                return "PorletDataNewsService";
            }
        }

        public override string ServiceName
        {
            get
            {
                return "Tin tức";
            }
        }

        public override bool RequiredData
        {
            get
            {
                return true;
            }
        }

        public override Collection<PorletDataItemCls> GetPorletDataItems(string SiteId)
        {
            //reading
            SiteParam OSiteParam=WebEnvironments.CreateSiteParam(SiteId);
            GroupDataCls[] CmsGroupDatas=CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).ReadingGroupData(SiteId, "news", OSiteParam.SiteCode);
            Collection<PorletDataItemCls> ColPorletDataItems = new Collection<PorletDataItemCls> { };
            for (int iIndex = 0; iIndex < CmsGroupDatas.Length; iIndex++)
            {
                string Id = CmsGroupDatas[iIndex].GroupDataId;
                string Subject = CmsGroupDatas[iIndex].GroupDataName;
                ColPorletDataItems.Add(new PorletDataItemCls(ServiceId, Id, Subject));
            }
            return ColPorletDataItems;
        }

        public override PorletDataItemCls CreatePorletDataItemModel(string SiteId, string PorletDataItemId)
        {
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            GroupDataCls CmsGroupData = CmsUtility.CreateCmsBussinessProcess(SiteId).CreateCmsProcess(SiteId).CreateGroupDataModel(null, SiteId, PorletDataItemId);
            PorletDataItemCls OPorletDataItem = new PorletDataItemCls(ServiceId, CmsGroupData.GroupDataId, CmsGroupData.GroupDataName);
            return OPorletDataItem;
        }
    }
}
